package com.niit.bc.util.web;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {
    private String path = "/jdbc.properties";

    public String getPropertie(String key) {
        String result = "";

        try {
            InputStream in = getClass().getResourceAsStream(path);
            Properties pro = new Properties();
            pro.load(in);
            result = pro.getProperty(key);
            pro.clear();
            in.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public String getPropertie(String path, String key) {
        this.path = path;
        return getPropertie(key);
    }

    public void setPropertie(String key, String value) {
        InputStream in;
        try {
            in = new FileInputStream(path);
            Properties pro = new Properties();
            pro.load(in);

            pro.setProperty(key, value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setPropertie(String path, String key, String value) {
        this.path = path;
        setPropertie(key, value);

    }

    public static void main(String[] arg) {
        PropertiesUtil util = new PropertiesUtil();
        String url = util.getPropertie("jdbc.url");
        System.out.println(url);
    }
}
